package com.ad.pet.app.type.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.models.remote.type.FirstCategroy;

import java.util.List;

/**18502131930
 * Created by SEELE on 2018/8/2.
 */

public class TypeMainAdapter extends BaseQuickAdapter<FirstCategroy,BaseViewHolder> {
    public TypeMainAdapter( @Nullable List<FirstCategroy> data) {
        super(R.layout.item_ali_type_main_layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final FirstCategroy item) {
        TextView tv_title = helper.getView(R.id.tv_title);
        tv_title.setText(item.getName());
        RecyclerView recyclerView = helper.getView(R.id.recycler_view);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext,3);
        recyclerView.setLayoutManager(gridLayoutManager);
        final TypeGoodAdapter aliTypeGoodAdapter = new TypeGoodAdapter(item.getSub_category_list());
        recyclerView.setAdapter(aliTypeGoodAdapter);
        aliTypeGoodAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
//                Navigation.goGoodDetail((Activity) mContext, MainActivity.REQUEST_GO_MALL,"523216");
//                    if (TextUtils.isEmpty(aliTypeGoodAdapter.getData().get(position).getSearch_name())){
//                        Events.TypeChose typeChose = new Events.TypeChose(aliTypeGoodAdapter.getData().get(position).getParent_id(),aliTypeGoodAdapter.getData().get(position).getId(),2);
//                        RxBus.getDefault().post(typeChose);
//                            ((MainActivity)mContext).mTabLayout.setCurrentTab(0);
//                    }else {

                        Navigation.goSerachEnd((Activity) mContext,aliTypeGoodAdapter.getData().get(position).getSearch_name(), MainActivity.REQUEST_GO_MALL,aliTypeGoodAdapter.getData().get(position).getId(),"");
//                    }

            }
        });
    }
}
